# -*- coding: UTF-8 -*-
from django.contrib import admin
from django.utils.translation import gettext_lazy as _
from .models import Customer, Contactor


class ContactorInline(admin.TabularInline):
    model = Contactor
    extra = 1
    fields = ['name', 'description', 'gender', 'note']


@admin.register(Customer)
class CustomerAdmin(admin.ModelAdmin):
    list_display = ['name', 'code', 'description', 'address', 'state', 'city', 'telephone', 'mail', 'zip_code', 'importance']
    list_display_links = ['name']
    search_fields = ['name', 'code', 'description']
    list_filter = ['importance', 'state', 'city']
    inlines = [ContactorInline]
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('name', 'code', 'description', 'importance')
        }),
        (_('联系信息'), {
            'fields': ('address', 'state', 'city', 'telephone', 'mail', 'zip_code')
        }),
    )
    
    
@admin.register(Contactor)
class ContactorAdmin(admin.ModelAdmin):
    list_display = ['name', 'description', 'gender', 'customer', 'note']
    list_display_links = ['name']
    search_fields = ['name', 'description']
    list_filter = ['gender', 'customer']
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('name', 'description', 'gender', 'customer')
        }),
        (_('其他信息'), {
            'fields': ('note',)
        }),
    ) 